import React from "react";
import {Button as AntButton} from "antd";

import BaseComponent from "../BaseComponent";

export default class Button extends BaseComponent {

    static defaultProps = {
        stopPropagation: true,//是否阻止冒泡
        preventDefault: true//是否阻止默认行为
    };

    render() {
        let options = {...this.props};
        options.onClick = (event) => {
            let {stopPropagation, preventDefault} = this.props;
            try {
                if (stopPropagation) {
                    event.stopPropagation();
                }
                if (preventDefault) {
                    event.preventDefault();
                }
            } catch (e) {

            }
            if (this.props.onClick) {
                this.props.onClick(event);
            }
        };
        delete options.stopPropagation;
        delete options.preventDefault;
        return (
            <AntButton {...options}>
                {this.props.children}
            </AntButton>
        )
    }
}
